<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="标题" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入标题" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable size="small" v-model="queryParams.date" type="date" value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['Productionline:dzc:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['Productionline:dzc:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['Productionline:dzc:remove']">删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['Productionline:dzc:export']">导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dzcList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="日期" align="center" prop="id" /> -->
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)">查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['Productionline:dzc:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['Productionline:dzc:remove']">删除</el-button>
          <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport(scope.row)"
            v-hasPermi="['Productionline:dzc:export']">导出</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改电子秤标量报对话框 -->
    <el-dialog :title="title" class="dzc-dialog" :visible.sync="open" width="1300px" append-to-body  v-myDialogDrag>
      <TableHeader2 :data="{
        mainTitle: '电子秤校准记录表',
        company: '',
        code: '',
    }" />
      <el-form ref="form" :model="form" :rules="rules" label-width="0px">
        <el-row style=" background: rgba(9, 34, 79, 0.22);" class="dzc-el-row">
          <el-col class="dzc-el-row " :span="24" style="border-bottom: 1px solid rgba(31, 179, 255, 0.2);">
            <el-col :span="8">
              <el-form-item prop="date">
                <el-date-picker clearable size="small" v-model="form.date" type="date" value-format="yyyy-MM-dd"
                  placeholder="选择日期" :disabled="openDisabled">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="4" class="border-col">
            <el-form-item prop="title">
              <el-input :rows="16" type="textarea" v-model="form.title" placeholder="请输入标题" :disabled="openDisabled" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-col :span="24" class="dzc-el-col">
              <p>电子秤位置</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <p>左上角</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <p>右上角</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <p>中央</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <p>左下角</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <p>右下角</p>
            </el-col>
          </el-col>
          <el-col :span="5">
            <el-col :span="24" class="dzc-el-col">
              <p>砝码重量/s</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="lua">
                <el-input v-model="form.lua" placeholder="请输入左上砝码" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="rua">
                <el-input v-model="form.rua" placeholder="请输入右上砝码" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="ca">
                <el-input v-model="form.ca" placeholder="请输入中间砝码" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="lda">
                <el-input v-model="form.lda" placeholder="请输入左下砝码" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="rda">
                <el-input v-model="form.rda" placeholder="请输入右下砝码" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="5">
            <el-col :span="24" class="dzc-el-col">
              <p>读数/g</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="lub">
                <el-input v-model="form.lub" placeholder="请输入左上读数" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="rub">
                <el-input v-model="form.rub" placeholder="请输入右上读数" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="cb">
                <el-input v-model="form.cb" placeholder="请输入中间读数" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="ldb">
                <el-input v-model="form.ldb" placeholder="请输入左下读数" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="rdb">
                <el-input v-model="form.rdb" placeholder="请输入右下读数" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="5">
            <el-col :span="24" class="dzc-el-col">
              <p>误差</p>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="luc">
                <el-input v-model="form.luc" placeholder="请输入左上误差" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="ruc">
                <el-input v-model="form.ruc" placeholder="请输入右上误差" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="cc">
                <el-input v-model="form.cc" placeholder="请输入中间误差" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="ldc">
                <el-input v-model="form.ldc" placeholder="请输入左下误差" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
            <el-col :span="24" class="dzc-el-col">
              <el-form-item prop="rdc">
                <el-input v-model="form.rdc" placeholder="请输入右下误差" :disabled="openDisabled" />
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listDzc, getDzc, delDzc, addDzc, updateDzc } from "@/api/quality/laboratory/dzc";
  import TableHeader2 from "@/components/table/tableData/header2.vue";
  export default {
    name: "Dzc",
    components: { TableHeader2 },
    data() {
      return {
        //弹窗是否禁止编辑
        openDisabled: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 电子秤标量报表格数据
        dzcList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          title: null,
          date: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          title: {
            required: true,
            message: "请输入标题",
            trigger: "blur",
          },
          date: {
            required: true,
            message: "请选择日期",
            trigger: "blur",
          },
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询电子秤标量报列表 */
      getList() {
        this.loading = true;
        listDzc({...this.queryParams,remark:'1'}).then(response => {
          this.dzcList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          title: null,
          date: null,
          lua: null,
          lub: null,
          luc: null,
          rua: null,
          rub: null,
          ruc: null,
          ca: null,
          cb: null,
          cc: null,
          rda: null,
          rdb: null,
          rdc: null,
          lda: null,
          ldb: null,
          ldc: null,
          factoryId: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null,
          remark: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.openDisabled = false;
        this.open = true;
        this.title = "添加电子秤标量报";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.openDisabled = false;
        const id = row.id || this.ids
        getDzc(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改电子秤标量报";
        });
      },
      /** 查看按钮 */
      handleView(row) {
        this.reset();
        this.openDisabled = true;
        const id = row.id || this.ids
        getDzc(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "查看电子秤标量报";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateDzc({...this.form,remark:'1'}).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              const rLoading = this.openLoading();
              addDzc({...this.form,remark:'1'}).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                rLoading.close();
                this.getList();
              }).catch((error) => {
                rLoading.close();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除电子秤标量报编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delDzc(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => { });
      },
      /** 导出按钮操作 */
      handleExport(row) {
        this.download('Laboratory/dzc/export?id=' + row.id,{}, '电子秤标量报' + this.parseTime(new Date) + '.xlsx')
      }
    }
  };
</script>
<style lang="scss" scoped>
  ::v-deep .dzc-el-row {
    /* padding: 15px 20px; */
    color: #ffffff;
    /* background: rgba(9, 34, 79, 0.22); */
    font-size: 14px;
    border: 1px solid rgba(31, 179, 255, 0.2);
    height: 70px;
  }

  ::v-deep .border-col {
    height: 409px;
    display: flex;
    align-items: center;
    border-right: 1px solid rgba(31, 179, 255, 0.2);
    border-bottom: 1px solid rgba(31, 179, 255, 0.2);
    border-left: 1px solid rgba(31, 179, 255, 0.2);
  }

  ::v-deep .dzc-el-col {
    p {
      display: flex;
      align-items: center;
      justify-content: center;
      color: #ffffff;
      /* padding:10px 0; */
      height: 38px;
    }

    border-bottom: 1px solid rgba(31, 179, 255, 0.2);
    border-right: 1px solid rgba(31, 179, 255, 0.2);
  }
</style>
